package com.turnengine.client.local.unit.bean;

import org.apache.commons.lang.builder.CompareToBuilder;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

/**
 * The Storage Group.
 */
public class StorageGroup implements IStorageGroup, Comparable<IStorageGroup> {

	/** The parent. */
	private int parent = -1;
	/** The group. */
	private int group = -1;
	/** The capacity. */
	private long capacity = 0;

	/**
	 * Creates a new Storage Group.
	 */
	public StorageGroup() {
	}

	/**
	 * Creates a new Storage Group.
	 * @param parent the parent
	 * @param group the group
	 * @param capacity the capacity
	 */
	public StorageGroup(int parent, int group, long capacity) {
		setParent(parent);
		setGroup(group);
		setCapacity(capacity);
	}

	/**
	 * Creates a new Storage Group.
	 * @param storageGroup the storage group
	 */
	public StorageGroup(StorageGroup storageGroup) {
		setParent(storageGroup.getParent());
		setGroup(storageGroup.getGroup());
		setCapacity(storageGroup.getCapacity());
	}

	/**
	 * Creates a new Storage Group.
	 * @param iStorageGroup the i storage group
	 */
	public StorageGroup(IStorageGroup iStorageGroup) {
		setParent(iStorageGroup.getParent());
		setGroup(iStorageGroup.getGroup());
		setCapacity(iStorageGroup.getCapacity());
	}

	/**
	 * Returns the parent.
	 * @return the parent.
	 */
	public int getParent() {
		return parent;
	}

	/**
	 * Returns the group.
	 * @return the group.
	 */
	public int getGroup() {
		return group;
	}

	/**
	 * Returns the capacity.
	 * @return the capacity.
	 */
	public long getCapacity() {
		return capacity;
	}

	/**
	 * Sets the parent.
	 * @param parent the parent to set.
	 */
	public void setParent(int parent) {
		this.parent = parent;
	}

	/**
	 * Sets the group.
	 * @param group the group to set.
	 */
	public void setGroup(int group) {
		this.group = group;
	}

	/**
	 * Sets the capacity.
	 * @param capacity the capacity to set.
	 */
	public void setCapacity(long capacity) {
		this.capacity = capacity;
	}

	/**
	 * Returns the hash code.
	 * @return the hash code.
	 */
	@Override
	public int hashCode() {
		HashCodeBuilder hash = new HashCodeBuilder(1123, 37);
		hash.append(parent);
		hash.append(group);
		hash.append(capacity);
		return hash.toHashCode();
	}

	/**
	 * Returns true if this is equal to the given object.
	 * @param object the object to compare.
	 * @return true if this is equal to the given object.
	 */
	@Override
	public boolean equals(Object object) {
		if (object == this) {
			return true;
		}
		if (object instanceof StorageGroup) {
			StorageGroup compare = (StorageGroup) object;
			EqualsBuilder equals = new EqualsBuilder();
			equals.append(this.parent, compare.parent);
			equals.append(this.group, compare.group);
			equals.append(this.capacity, compare.capacity);
			return equals.isEquals();
		}
		return false;
	}

	/**
	 * Compare this to the given object.
	 * @param compare the object to compare to.
	 * @return the result of the comparison.
	 */
	@Override
	public int compareTo(IStorageGroup compare) {
		CompareToBuilder builder = new CompareToBuilder();
		builder.append(this.parent, compare.getParent());
		builder.append(this.group, compare.getGroup());
		builder.append(this.capacity, compare.getCapacity());
		return builder.toComparison();
	}

	/**
	 * Returns this as a string.
	 * @return this as a string.
	 */
	@Override
	public String toString() {
		ToStringBuilder string = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE);
		string.append("parent", parent);
		string.append("group", group);
		string.append("capacity", capacity);
		return string.toString();
	}
}
